﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ARCam3D.Tuple
{
    public class Vector2D : Tuple2D
    {
        public Vector2D() : base() { }

        public Vector2D(double x, double y) : base(x, y) { }

        public Vector2D(Tuple2D tuple) : base(tuple) { }

        public Vector2D(Point2D p1, Point2D p2) : base(p2.x - p1.x, p2.y - p1.y) { }

        public double Length
        {
            get { return Math.Sqrt(x * x + y * y); }
        }

        public double PolarAngle
        {
            get
            {
                if (this.x == 0 && this.y == 0)
                {
                    return 0;
                }

                double angle = Math.Acos(this.x / Length);

                if (y < 0)
                {
                    angle = 2 * Math.PI - angle;
                }

                return angle;
            }
        }

        public Vector2D Normalize()
        {
            double length = Length;

            x = x / length;
            y = y / length;

            return this;
        }

        public Vector2D Add(Vector2D vector)
        {
            x = x + vector.x;
            y = y + vector.y;

            return this;
        }

        public double ScalarMul(Vector2D vector)
        {
            return this.x * vector.x + this.y * vector.y;
        }

        public double GetAngle(Vector2D vector)
        {

            return Math.Acos(ScalarMul(vector) / (this.Length * vector.Length));
        }
    }
}
